package com.wuze.cloud.handler;

import com.wuze.cloud.request.SysFileChunkQuery;
import com.wuze.cloud.util.FileConvertUtil;
import com.wuze.cloud.util.FileUtil;
import org.assertj.core.util.Lists;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.File;
import java.util.List;

/**
 * @author: wuze
 * @description:
 * @date: 2023/03/16
 */
@Component
public class WordHandler implements FileHandler {

    @Value("${file.accessPath}")
    private String accessPath;

    @Value("${file.uploadFolder}")
    private String uploadFolder;

    @Override
    public List<String> tags() {
        return Lists.newArrayList(".docx",".doc");
    }

    @Override
    public String handler(SysFileChunkQuery query) {
        String path = query.getPath();
        File file = new File(path);
        byte[] bytes = FileUtil.file2byte(file);
        FileConvertUtil.wordBytes2HtmlFile(bytes,uploadFolder+"\\html\\"+query.getOpenKey()+".html");
        return accessPath+"html/"+query.getOpenKey()+".html";
    }
}
